#include <cstdio>
typedef long long LL;
LL fast_power_recursion(LL a, LL b, LL m)
{
    LL tmp;
    if (0 == b)
    {
        return 1;
    }
    if (b & 1) //(1 == b % 2)//b为奇数
        return fast_power_recursion(a, b - 1, m) * a % m;
    else //b为偶数
    {
        tmp = fast_power_recursion(a, b / 2, m);
        return tmp * tmp % m;
    }
}
LL fast_power_iteration(LL a, LL b, LL m)
{
    LL res = 1;
    while (b > 0)
    {
        if (b & 1)//***
        {
            res = res * a % m;//***
        }
        a = a * a % m;
        b >>= 1;//b>>1***
    }
    return res;
}
int main()
{
    LL a, b, m;
    scanf("%ld%ld%ld", &a, &b, &m);
    LL res = fast_power_recursion(a, b, m);
    printf("res = %d\n", res);
    return 0;
}